package com.doone.telmarket.action.admin;

import java.util.List;

import org.apache.log4j.Logger;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.doone.telmarket.domain.ibator.ServiceType;
import com.doone.telmarket.service.ServiceTypeOperation;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @package com.doone.telmarket.web.action
 * @author 甘雨波
 * @date 2009-9-14 10:33
 * @description 增值业务相关操作Action
 *
 */
@ParentPackage("struts-default")
@Service("serviceTypeAction")
public class ServiceTypeAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	Logger log = Logger.getLogger(ServiceTypeAction.class);
	
	@Autowired
	private ServiceTypeOperation remoteServiceTypeOperation;

	/*增值业务服务类别名称*/
	private String serviceTypeName;

	private List<ServiceType> serviceTypeList;

	private String serviceTypeId;

	private String page;

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	/**
	 * @description 保存增值业务服务类别
	 * @author 甘雨波
	 * @date 2009-9-14 10:41
	 * @return
	 */
	@Action(value = "saveServiceType", results = { @Result(name = "success", location = "/admin/success.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String saveServiceType() {
		try {
			ServiceType serviceType = new ServiceType();
			serviceType.setServiceTypeName(serviceTypeName);
			//log.info("传入的NAME为：" + serviceTypeName);
			int id = remoteServiceTypeOperation.saveIsmpServiceType(serviceType);
			if (id == 0)
				return "error";
			page = "service/serviceType.jsp";
			return "success";
		} catch (Exception e) {
			log.info("新增增值业务服务类别" + e.getMessage());
			return "error";
		}

	}

	/**
	 * @description 获取所有增值业务服务类别列表
	 * @author 甘雨波
	 * @date 2009-9-15 10:13
	 * @return
	 */
	@Action(value = "toDeleteServiceType", results = {
			@Result(name = "success", location = "/admin/service/deleteServiceType.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String selectAllServiceType() {
		try {
			serviceTypeList = remoteServiceTypeOperation.selectAllServiceType();
			//log.info(serviceTypeList.size());
			return "success";
		} catch (Exception e) {
			log.info("获取增值业务服务类别列表失败" + e.getMessage());
			return "error";
		}

	}

	/**
	 * @description 删除增值业务服务类别
	 * @author 甘雨波
	 * @date 2009-9-15 10:25
	 * @return
	 */
	@Action(value = "deleteServiceType", results = { @Result(name = "success", location = "/admin/success.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String deleteServiceType() {
		try {
			remoteServiceTypeOperation.deleteIsmpServiceType(Integer.parseInt(serviceTypeId));
			page = "toDeleteServiceType";
			return "success";
		} catch (Exception e) {
			log.info("删除增值业务服务类别失败" + e.getMessage());
			return "error";
		}

	}

	/**
	 * @description 编辑增值业务服务类别
	 * @author 甘雨波
	 * @date 2009-9-14 10:55
	 * @return
	 */
	@Action(value = "updateServiceType", results = { @Result(name = "success", location = "/admin/success.jsp"),
			@Result(name = "error", location = "/admin/error.jsp") })
	public String updateServiceType() {
		try {
			ServiceType s = new ServiceType();
			s.setServiceTypeId(Integer.parseInt(serviceTypeId));
			s.setServiceTypeName(serviceTypeName);
			//log.info("ID>>>"+serviceTypeId);
			//log.info("NAME>>>"+serviceTypeName);
			remoteServiceTypeOperation.updateIsmpServiceType(s);
			page = "toDeleteServiceType";
			return "success";
		} catch (Exception e) {
			log.info("编辑增值业务服务类别失败" + e.getMessage());
			return "error";
		}
	}

	public String getServiceTypeName() {
		return serviceTypeName;
	}

	public void setServiceTypeName(String serviceTypeName) {
		this.serviceTypeName = serviceTypeName;
	}

	public List<ServiceType> getServiceTypeList() {
		return serviceTypeList;
	}

	public void setServiceTypeList(List<ServiceType> serviceTypeList) {
		this.serviceTypeList = serviceTypeList;
	}

	public String getServiceTypeId() {
		return serviceTypeId;
	}

	public void setServiceTypeId(String serviceTypeId) {
		this.serviceTypeId = serviceTypeId;
	}

}
